package br.ufrgs.tst.ga.model;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import br.ufrgs.ga.model.GeneticModelFactory;
import br.ufrgs.ga.model.IChromosome;

public class TestChromosome {

	public static final String EXPECTED_DNA_STRAND = "012125";

	private GeneticModelFactory factory;
	
	/**
	 * Chromosome under test.
	 */
	private IChromosome<String> chromosome;
	
	/**
	 * Auxiliary chromosome to test the reproduct operation.
	 */
	private IChromosome<String> otherChromosome;
	
	@Before
	public void setUp() {
		this.factory = GeneticModelFactory.getInstance();
		this.chromosome = factory.createChromosome("012345");
		this.otherChromosome = factory.createChromosome("000125");
	}
	
	@Test
	public void reproductionTest() {
		IChromosome<String> child = chromosome.reproduce(otherChromosome);
		Assert.assertEquals(EXPECTED_DNA_STRAND, child.getDnaStrand());
	}
	
	@Test
	public void isValidTest() {
		Assert.assertTrue(chromosome.isValid("123123"));
		Assert.assertFalse(chromosome.isValid("12312asda dsa3"));
		Assert.assertFalse(chromosome.isValid("+_)(*&¨&%$$#@ {`}^:sda2342"));
		Assert.assertFalse(chromosome.isValid("012346"));
		Assert.assertFalse(chromosome.isValid(""));
		Assert.assertFalse(chromosome.isValid(null));
	}
	
	@Test
	public void cloneTest() throws CloneNotSupportedException {
		IChromosome<String> clonedChromosome = chromosome.clone();
		Assert.assertEquals(chromosome.getDnaStrand(), clonedChromosome.getDnaStrand());
	}

	@Test
	public void equalsTest() throws CloneNotSupportedException {
		Assert.assertTrue(chromosome.equals(chromosome));
		Assert.assertTrue(chromosome.equals(chromosome.clone()));
		Assert.assertFalse(chromosome.equals(otherChromosome));
		Assert.assertFalse(chromosome.equals(null));
	}
}
